﻿namespace RMServiceRIA
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using System.Windows;
    using System;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Rooms : Page
    {
        rService.Service1Client svc = new rService.Service1Client();
        /// <summary>
        /// Creates a new <see cref="Rooms"/> instance.
        /// </summary>
        public Rooms()
        {
            InitializeComponent();            
            this.Title = "Rooms";
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            HeaderText.Text = ((App)Application.Current).session.building.Name;
            svc.getRoomsBuildingCompleted += new EventHandler<rService.getRoomsBuildingCompletedEventArgs>(svc_getRoomsBuildingCompleted);
            svc.getRoomsBuildingAsync(((App)Application.Current).session.building.BuildingID);
        }

        void svc_getRoomsBuildingCompleted(object sender, rService.getRoomsBuildingCompletedEventArgs e)
        {
            ((App)Application.Current).session.roomBuilding = e.Result;
            cBox.ItemsSource = ((App)Application.Current).session.roomBuilding;
        }

        private void cBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((App)Application.Current).session.room = (rService.ReserveMeRoom)((ComboBox)sender).SelectedItem;
            NavigationService.Navigate(new Uri("/SelectedRoom", UriKind.RelativeOrAbsolute));
        }     
    }
}